package com.javaee.controller;

import java.util.HashMap;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.javaee.util.ResultOutDto;
import com.javaee.weixin.util.ReadPackUtils;

/**
 * 微信红包
 * 刘云龙
 */
@Controller
@RequestMapping("/front/RedPackApi")
public class RedPackApiController{
	private static String sendName = "抵奥云科技";
	//微信证书路径
	private static String certPath = "/opt/cert/apiclient_cert.p12";//改成自己的
	//商户相关资料
	String wxappid = "xxxxxxx";//改成自己的
	// 微信支付分配的商户号
	String partner ="xxxxxx";//改成自己的
	//API密钥
	String paternerKey = "xxxxxxxxxxx";//改成自己的


	/**
	 * 发送普通红包
	 */
	@ResponseBody
	@RequestMapping("/sendredpack")
	public ResultOutDto sendredpack(HttpServletRequest request) {
		String total_amount = request.getParameter("total_amount");//红包总金额
		String total_num = request.getParameter("total_num");//红包发放个数
		String wishing = request.getParameter("wishing");//红包祝福语
		String act_name = request.getParameter("act_name");//活动名称
		String remark = request.getParameter("remark");//备注
		String reOpenid = request.getParameter("reOpenid");//用户openid
		
		HashMap<Object, Object> map = new HashMap<Object,Object>();
		boolean isSend = ReadPackUtils.sendredpack(request, total_amount, total_num, wishing,
				act_name, remark, reOpenid,
				partner, wxappid, sendName, paternerKey, certPath);
		if(isSend==true){
			map.put("success", "红包发送成功!");
			return ResultOutDto.ok(map);
		}else{
			map.put("fail", "红包发送失败!");
			return ResultOutDto.ok(map);
		}
	}
	
	
	/**
	 * 查询红包
	 */
	public void query() {
		String query = ReadPackUtils.query("10000098201411111234567890", partner, wxappid, paternerKey, certPath);
		
	}

}